#ifndef _COMPRESS_NEW_
#define _COMPRESS_NEW_


#define N       4096    /* buffer size */
#define F       60  /* lookahead buffer size */
#define THRESHOLD   2
#define NIL     N   /* leaf of tree */

#define N_CHAR      (256 - THRESHOLD + F)
                /* kinds of characters (character code = 0..N_CHAR-1) */
#define T       (N_CHAR * 2 - 1)    /* size of table */
#define R       (T - 1)         /* position of root */
#define MAX_FREQ    0x8000      /* updates tree when the */


#include "CrypFun.h"

int Expand (DATA * buffer);
int Compress (DATA * buffer);
		
extern DATA inbuffer, outbuffer;
extern unsigned long int textsize, codesize, printcount;
	
int Encode(void);
int Decode(void);
void InitVar(void);

extern unsigned char text_buf[N + F - 1];
extern int match_position, match_length, lson[N + 1], rson[N + 257], dad[N + 1];
extern unsigned freq[T + 1];		/* frequency table */
extern int prnt[T + N_CHAR];		/* pointers to parent nodes, except for the */
	    /* elements [T..T + N_CHAR - 1] which are used to get */
            /* the positions of leaves corresponding to the codes. */

extern int son[T];			/* pointers to child nodes (son[], son[] + 1) */

extern unsigned getbuf;
extern unsigned char getlen;
extern unsigned long incount, outcount;
extern unsigned putbuf;
extern unsigned char putlen;
extern unsigned code0, len;

void Error (char *message);
void freememory(void);
void InitTree(void);
void InsertNode(int r);
void DeleteNode(int p);
int GetBit(void);
int GetByte(void);
void Putcode (int l, unsigned c);
void StartHuff(void);
void reconst(void);
void update (int c);
void EncodeChar (unsigned c);
void EncodePosition (unsigned c);
void EncodeEnd(void);
int DecodeChar(void);
int DecodePosition(void);
#endif
